import smtplib
import time
from email import encoders
from email.mime.base import MIMEBase

from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.common.touch_action import TouchAction
def login(driver):
    # 同意用户协议
    el1 = driver.find_element(AppiumBy.ID, "com.tencent.now:id/c2o")
    el1.click()
    time.sleep(8)
    # 点击同意登录协议
    el2 = driver.find_element(AppiumBy.ID, "com.tencent.now:id/d9w")
    el2.click()
    time.sleep(2)
    # 点击qq登录
    el3 = driver.find_element(AppiumBy.ID, "com.tencent.now:id/of")
    el3.click()
    time.sleep(10)
    # 同意授权登录
    el4 = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "同意")
    el4.click()
    time.sleep(10)
    # 青少年保护协议
    el5 = driver.find_element(AppiumBy.ID, "com.tencent.now:id/cv3")
    el5.click()
    time.sleep(2)



"""
    使用smtp发送邮件
    :param mail_sender: 发件人
    :param to_list: 收件人列表，用,间隔
    :param sub: 主题
    :param content: 内容
    :param attach_list:附件
    :param _subtype: 读取内容用的方式，不传html的话改成plain
    :return:
    """
def sendEmail(mail_sender, to_list,sub, content, attach_list = [], _subtype="html"):
    # 发件人邮箱地址
    from_email = mail_sender
    # 收件人邮箱地址
    to_emails = to_list
    # 邮件主题
    subject = sub
    # 邮件正文
    body = content
    # 附件文件路径
    attachment_paths = attach_list

    # 创建MIMEMultipart对象
    msg = MIMEMultipart()
    msg["From"] = from_email
    msg["To"] = ", ".join(to_emails)
    msg["Subject"] = subject

    # 添加邮件正文
    msg.attach(MIMEText(body, "plain"))

    # 添加附件
    for attachment_path in attachment_paths:
        print(attachment_path)
        with open(attachment_path, "rb") as attachment:
            part = MIMEBase("application", "octet-stream")
            part.set_payload(attachment.read())
            encoders.encode_base64(part)
            part.add_header(
                "Content-Disposition", f"attachment; filename= {attachment_path}"
            )
            msg.attach(part)

    # 连接到SMTP服务器并发送邮件
    server = smtplib.SMTP("smtp.qq.com", 25)
    server.starttls()
    server.login(from_email, "zxczcaunzcqnfgda")
    text = msg.as_string()
    for to_email in to_emails:  # 遍历收件人地址列表并发送邮件
        server.sendmail(from_email, to_email, text)
    server.quit()